<template>
  <a-modal :maskClosable="false"
    :title="title"
    :width="800"
    :visible="visible"
    :confirmLoading="confirmLoading"
    @ok="handleOk"
    @cancel="handleCancel"
    cancelText="关闭">
    <a-spin :spinning="confirmLoading">
      <div class="clearfix">
        <a-upload
          :action="uploadAction"
          :multiple="isMultiple"
          list-type="picture-card"
          :file-list="fileList"
          @preview="handlePreview"
          @change="handleChange"
        >
          <div v-if="fileList.length < 8">
            <a-icon type="plus" />
            <div class="ant-upload-text">
              上传
            </div>
          </div>
        </a-upload>
        <a-modal :maskClosable="false" :visible="previewVisible" :footer="null" @cancel="handleCancel">
          <img alt="example" style="width: 100%" :src="previewImage" />
        </a-modal>
      </div>
    </a-spin>
  </a-modal>
</template>

<script>
import { httpAction, putAction, getAction, postAction } from '@api/manage'
import moment from 'moment'

export default {
  name: 'HHisApprovalModal',
  data() {
    return {
      title: '操作',
      visible: false,
      confirmLoading:false,
      previewVisible: false,
      previewImage: '',
      fileList: [],
      url: {
        add: '/his/administrative/approval',
        edit: '/his/administrative/approval'
      },
      uploadAction:window._CONFIG['domianURL']+"/sys/common/upload",
      isMultiple:true
    }
  },
  created() {
  },
  methods: {
    add() {
      this.visible = true
    },
    edit(record) {
      this.visible = true
    },
    close() {
      this.$emit('close')
      this.visible = false
    },
    handleOk() {
      const that = this
      console.log(this.fileList)
    },
    handleCancel() {
      this.close()
    },
    async handlePreview(file) {
      if (!file.url && !file.preview) {
        file.preview = await getBase64(file.originFileObj);
      }
      this.previewImage = file.url || file.preview;
      this.previewVisible = true;
    },
    handleChange(info) {
      this.picUrl = false;
      let fileList = info.fileList
      //update-begin-author:wangshuai date:20201022 for:LOWCOD-969 判断number是否大于0和是否多选，返回选定的元素。
      if(this.number>0 && this.isMultiple){
        fileList = fileList.slice(-this.number);
      }
      //update-end-author:wangshuai date:20201022 for:LOWCOD-969 判断number是否大于0和是否多选，返回选定的元素。
      if(info.file.status==='done'){
        if(info.file.response.success){
          this.picUrl = true;
          fileList = fileList.map((file) => {
            if (file.response) {
              file.url = file.response.message;
            }
            return file;
          });
        }
        //this.$message.success(`${info.file.name} 上传成功!`);
      }else if (info.file.status === 'error') {
        this.$message.error(`${info.file.name} 上传失败.`);
      }else if(info.file.status === 'removed'){
        this.handleDelete(info.file)
      }
      this.fileList = fileList
    },

  }
}
</script>

<style scoped>

</style>